<?php

namespace app\index\controller;

use think\Controller;
use think\View;
//公用控制器
class Common extends Controller
{
//    相当于钩子函数
    public function _initialize()
    {
       $this->getAllCate();
//        echo 123;
    }


    public function getAllCate()
    {
//        获取所有的顶级分类
        $top = db('cate')->where(array('pid'=>0))->select();
//        循环顶级分类，看是否有子分类
        foreach ($top as $k=>$v){
//            dump($v);
            $son = db('cate')->where(array('pid'=>$v['id']))->select();
            if ($son){
                $top[$k]['son'] = $son;
            }else{
                $top[$k]['son'] = 0;
            }
        }
//        dump($top);
        $this->assign('top',$top);
    }





}
